package com.ms.game.slot.base;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;


/**
 * 連消爆炸
 * @author TW15012
 *
 */
public class SlobComboBombCounter 
{
	public void setNextSymbol(List<Integer> wheel , List<Integer> symbol , Integer maskID)
	{
		int idx=0;
		for(int i=0;i<wheel.size();i++)
		{
			if(wheel.get(i)==maskID)
			{
				wheel.set(i, symbol.get(idx));
				idx++;
			}
		}
	}
	
	/**
	 * 移動滾輪帶symbol
	 * @param wheel
	 * @param maskID
	 * @return
	 */
	public int moveWheelSymbol(List<Integer> wheel , Integer maskID)
	{
		//找第一個maskID，找不到就直接回傳(不需要位移)
		int frist = wheel.indexOf(maskID);
		if(frist<0 || frist==wheel.size()-1)
		{
			return -1;
		}
		
		//氣泡排序
		for (int i=0;i<wheel.size()-1;i++)
		{
			 for (int j=0;j<wheel.size()-i-1;j++)  
             {
				 if(wheel.get(j)==maskID)
				 {
					 wheel.set(j,wheel.get(j+1));
					 wheel.set(j+1,maskID);
				 }
             }
		}
		
		return frist;
	}
	
	/**
	 * 過瀘並設定己爆炸的symbol
	 * @return
	 */
	public void filterBombSymbol(ArrayList<Integer> screen , List<Integer> bombidx , int maskID)
	{
		for(int idx:bombidx)
		{
			screen.set(idx, maskID);
		}
	}
	
	public static void main(String[] args) 
	{
		Integer [] data = new Integer []{
			2,98,99,100,
			2,98,99,100,
			2,98,99,100,
			2,98,99,100,
			2,98,99,100
		};
		
		Integer[] symbol = new Integer[]{
			1,2,3,99,
			4,5,6,99,
			7,8,9,99,
			10,11,12,99,
			13,14,15,99
		};
		
		//己炸掉的symbol idx
		ArrayList<Integer> bomb = new ArrayList<Integer>();
		bomb.add(0);
		bomb.add(4);
		bomb.add(8);
		bomb.add(12);
		bomb.add(16);
		
		/*bomb.add(1);
		bomb.add(4);
		bomb.add(7);
		bomb.add(10);
		bomb.add(13);
		
		bomb.add(2);
		bomb.add(5);
		bomb.add(8);
		bomb.add(11);
		bomb.add(14);*/
		
		
		
		List<Integer> ss = Arrays.asList(data);
		List<Integer> sn = Arrays.asList(symbol);
		ArrayList<Integer> screen = new ArrayList<Integer>(ss);
		ArrayList<Integer> sym = new ArrayList<Integer>(sn);
		
		int maskid = 0;
		SlobComboBombCounter counter = new SlobComboBombCounter();
		counter.filterBombSymbol(screen, bomb, maskid);
		
		
		System.out.println(Arrays.toString(screen.toArray()));
		
		int p=0;
		for(int i=0;i<5;i++)
		{
			int to = p + 4;
			List<Integer> w = screen.subList(p, to);
			List<Integer> sy = sym.subList(p, to);
			
			counter.moveWheelSymbol(w, maskid);
			counter.setNextSymbol(w,sy, maskid);
			p=to;
		}
		
		System.out.println(Arrays.toString(screen.toArray()));
	}
}

